#设置虚拟内存（ES)
sysctl -w vm.max_map_count=262144
echo "vm.max_map_count=262144" >> /etc/sysctl.conf
sysctl -p

#创建网络
docker network create es

#创建目录&设置权限
sudo mkdir -p /home/es/01/
sudo mkdir -p /home/es/02/
sudo mkdir -p /home/es/03/
sudo chmod -R 777 /home/es

#运行容器1
docker kill es01
docker rm es01
docker run -d  \
-p 9200:9200 \
--restart=always \
--network es --network-alias es01 \
-v /home/es/01:/usr/share/elasticsearch/data \
-e "node.name=es01" -e "cluster.name=es-docker-cluster" \
-e "discovery.seed_hosts=es02,es03" -e "cluster.initial_master_nodes=es01,es02,es03" \
-e "bootstrap.memory_lock=true" -e "ES_JAVA_OPTS=-Xms512m -Xmx512m" \
--ulimit memlock=-1:-1 \
--name es01  elasticsearch:7.17.0

#运行容器2
docker kill es02
docker rm es02
docker run -d \
--restart=always \
--network es --network-alias es02 \
-v /home/es/02:/usr/share/elasticsearch/data \
-e "node.name=es02" -e "cluster.name=es-docker-cluster" \
-e "discovery.seed_hosts=es01,es03" -e "cluster.initial_master_nodes=es01,es02,es03" \
-e "bootstrap.memory_lock=true" -e "ES_JAVA_OPTS=-Xms512m -Xmx512m" \
--ulimit memlock=-1:-1 \
--name es02  elasticsearch:7.17.0

#运行容器3
docker kill es03
docker rm es03
docker run -d \
--restart=always \
--network es --network-alias es03 \
-v /home/es/03:/usr/share/elasticsearch/data \
-e "node.name=es03" -e "cluster.name=es-docker-cluster" \
-e "discovery.seed_hosts=es01,es02" -e "cluster.initial_master_nodes=es01,es02,es03" \
-e "bootstrap.memory_lock=true" -e "ES_JAVA_OPTS=-Xms512m -Xmx512m" \
--ulimit memlock=-1:-1 \
--name es03  elasticsearch:7.17.0